"use strict";
import { SCREEN_WIDTH } from "../constant";
const { View, ScrollView, Image, ActionSheetIOS } = require('react-native');
const ImagePicker = require('react-native-image-picker');
const ImageCrop = require('react-native-image-crop-picker').default;
const { Actions } = require("react-native-router-flux");
const _default = {
    options: {
        title: null,
        cancelButtonTitle: '取消',
        takePhotoButtonTitle: '拍摄照片',
        chooseFromLibraryButtonTitle: '选择现有照片',
        customButtons: null,
        cameraType: 'back',
        mediaType: 'photo',
        maxWidth: SCREEN_WIDTH,
        allowsEditing: false,
    },
    cropOptions: {
        mediaType: 'photo',
        width: SCREEN_WIDTH,
        cropperCircleOverlay: false,
        cropping: true
    }
};
class MyImagePicker {
    constructor() {
        this.options = {
            pickerOptions: {},
            cropOptions: {}
        };
    }
    showImagePicker() {
        return new Promise((resolve, reject) => {
            ImagePicker.showImagePicker(Object.assign({}, _default.options, this.options.pickerOptions, { allowsEditing: false }), (response) => {
                if (response.error) {
                    reject(new Error(response.error));
                }
                else if (response.didCancel) {
                    reject(new Error('user cancel'));
                }
                else {
                    if (this.options.pickerOptions.allowsEditing) {
                        ImageCrop.openCropper(Object.assign({}, _default.cropOptions, this.options.cropOptions, { path: response.uri })).then(image => {
                            resolve(Object.assign({}, response, image));
                        }).catch((e) => {
                        });
                    }
                    else {
                        resolve(response);
                    }
                }
            });
        });
    }
}
export default MyImagePicker;
